package com.ihealthway.all.groupbuy.modules.admin;

import com.ihealthway.all.slog.annotation.SLog;
import com.ihealthway.all.groupbuy.services.WinnerLogService;
import com.ihealthway.all.utils.Ajax;
import com.ihealthway.all.utils.AjaxReturn;
import com.ihealthway.all.commons.Constants;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * WinnerLog log module class
 * @author 凡梦星尘(elkan1788@gmail.com)
 */
@IocBean
@At("/admin/winner")
public class WinnerLogModule {

    private static final Log logger = Logs.get();

    @Inject
    private WinnerLogService winnerLogService;

    @At
    @Ok("beetl:admin/winnerlog.jsp")
    public void index(HttpServletRequest req) {
    }

    @POST
    @At
    @SLog(module = Constants.MODULE_USER, type = Constants.OPERATE_TYPE_UPDATE, content = "更新用户【${args[0]}】的中奖状态为: ${args[1]}")
    public AjaxReturn updateWinStatus(@Param("wlIds") String wlIds, @Param("status") Integer status) {
        logger.infof("Update win ids: %s, status: %d", wlIds, status);
        AjaxReturn ar = Ajax.ok();
        boolean flag = winnerLogService.updateWinnerStatus(wlIds, status);
        ar.setOk(flag);
        return ar;
    }


    @POST
    @At
    public Map<String, Object> dataList(int page, int rows, @Param("uName") String userName,
                                        @Param("startD") String sDate, @Param("endD") String eDate) {
        return winnerLogService.getDataList(page, rows, userName, sDate, eDate);
    }
}
